package com.pgyl.contract.controller;

import com.pgyl.contract.exceptions.ValidationException;
import com.pgyl.contract.model.Contract;
import com.pgyl.contract.service.ContractService;
import com.pgyl.contract.service.base.ContractServiceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通用的合同处理控制器
 * 含有销售合同和采购合同...
 */
@RestController
@RequestMapping("/contracts")
public class ContractController {

    @Autowired
    private ContractServiceFactory serviceFactory;

    @PostMapping
    public ResponseEntity<String> addContract(@RequestBody Contract contract) throws ValidationException {
        ContractService<Contract> service = serviceFactory.getService(contract);
        service.addContract(contract);
        return ResponseEntity.ok("合同处理成功");
    }
}
